/*==============================================================================
        This header contains description of particles system, which is
                 used to draw some nice video effects.
==============================================================================*/

#ifndef PARTICLES_H
#define PARTICLES_H

#include "effects.h"

/*==============================================================================
     Particle structure - describes needed characteristics of one particle.
==============================================================================*/
struct Particle
{
	float birth_time, death_time;
	Vector2 pos;
	Vector2 speed;
	Color color;
	float size;
};

/*==============================================================================
							Particles Effect
==============================================================================*/
class ParticleEffect : public Effect
{
public:
	ParticleEffect(Video* video = NULL, Sound* sound = NULL, const std::string &filename = "");
	virtual ~ParticleEffect();

	// Draw all particles on screen
	virtual void Render();
	// Update particles: creates, kills, updates position
	virtual void Update();

protected:
	// Adds new member to particles array
	void CreateParticle(float birth_time, Vector2 pos, Vector2 speed, ColorHSV col, float size);
	// Kills and draws a particle from particles array
	void KillParticle(int id);
	void DrawParticle(int id);

	// Updates particles[id] particle position
	virtual void UpdatePos(int id) = 0;

	// Array of particles
	Particle* particles;
	// Get number of maximum allowed particles at one time
	int GetMaxParticles();
	// Get current number of particles
	int GetParticlesCount();

	// Delta time
	float dt;

private:
	// Name of data file
	std::string data_filename;
	// Reads and tests data file
	void ReadData();
	void TestData();

	// Maximum number of particles allowed
	int max_particles;
	// Current number of created particles
	int particles_count;
	// Time when last particle born
	float last_particle_born;
	// Time, shows how long one particle exists
	float particle_lifetime;

	// Data from "particles.txt":
	// How frequently particles are created
	float emission_rate;
	// Particles starting position
	Vector2 start_pos;
	// Particles will have speed and size in range [min; max]
	Vector2 speed_min, speed_max;
	float size_min, size_max;

	// Time when system was updated last time
	float last_update_time;
};


#endif // PARTICLES_H